<template>
	<view class="content">
		<video class="video" :src="url"
			autoplay="true"></video>
		<view class="seg">
			评论
		</view>
		<u-line color="white"></u-line>
		<view class="comment-box">
			<view class="comments" v-for="(item,index) in dataList" :key="index">
				<view class="info-box">
					<view class="avatar-box">
						<image :src="item.avatar"
							style="width: 100rpx;height: 100rpx;"></image>
					</view>
					<view class="nickname">{{item.nickname}}</view>
				</view>
				<view class="comment">{{item.comment}}</view>
			</view>
		</view>
		<view class="input-box">
			<view class="in">
				<view>
					<image src="../../../static/icon/recovery_video/input.png" style="width: 40rpx;height: 40rpx;">
					</image>
				</view>
				<input placeholder="写评论..." class="input" placeholder-style="color:#333333" v-model="value" 
				@confirm="comment" adjust-position="false" :focus="bool_focus"></input>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [
				],
				value: '',
				type: 'text',
				border: true,
				loading: false,
				disabled: false,
				show: false,
				videoId:0,
				url:"",
				bool_focus:false
			}
		},
		onLoad(option) {
			this.videoId=option.videoId;
			this.getDetails();
		},
		methods: {
			getDetails(){
				var me=this;
				var usertoken = uni.getStorageSync("usertoken");
				uni.request({
					url: me.serverUrl + "/video/getVideoDetails",
					data: {
						"videoId": me.videoId
					},
					method: "POST",
					header: {
						"usertoken": usertoken
					},
					success(res) {
						console.log(res.data)
						if (res.data.status == 200) {
							me.url=res.data.url;
							me.dataList=res.data.commentsList;
							// me.dataList.unshift({
							// 	"nickname": info.ipname,
							// 	"content": me.value
							// })
							// me.sendCode();
						}
					}
				})
			},
			comment() {
				var me = this;
				if(me.value=="")
					return ;
				me.bool_focus=false;
				console.log("saa")
				var usertoken = uni.getStorageSync("usertoken");
				var info = uni.getStorageSync("accountInfo");
				uni.request({
					url: me.serverUrl + "/user/comment",
					data: {
						"openid": info.openid,
						"comment": me.value,
						"videoId":me.videoId
					},
					method: "POST",
					header: {
						"usertoken": usertoken
					},
					success(result) {
						console.log(result)
						if (result.data.status == 200) {
							me.dataList.unshift({
								"nickname": info.ipname,
								"comment": me.value,
								"avatar":info.avatar
							})
							uni.showToast({
								title:"评论成功"
							})
							me.value="";
							// me.sendCode();
						}
					}
				})
			},

		}
	}
</script>

<style>
	@import url("recovery-video-details.css");
</style>
